public class test3 {
    public static void main(String[] args) {
        Student[] student = new Student[5];
        student[0] = new Student(20165317, "nxy",20 ,85, 72, 95);
        student[1] = new Student(20165318, "sxx",20 ,87, 72, 93);
        student[2] = new Student(20165317, "gjt", 20,88, 73, 91);
        student[3] = new Student(20165316, "sxz", 20,99, 94, 56);
        student[4] = new Student(20165315, "yh",20 ,100, 100, 100);
        Student temp; //排序使用的临时对象
        //按sum排序
        for (int i = 0; i < student.length; i++) {
            for (int j = i+1; j < student.length; j++) {
                if(student[j].sum() > student[i].sum()){
                    temp = student[i];
                    student[i] = student[j];
                    student[j] = temp;
                }
            }
        }
        int mingci = 1;//名次

        for (int i = 0; i < student.length-1; i++) {
            int n = checkContinue(student, student[i].sum());
            if (n == 1) {
                student[i].mingci = mingci++;
            }else {
                //总分相同，名次相同
                for (int j = 0; j < n; j++) {
                    student[i+j].mingci = mingci;
                }
                mingci++;
                i = i + n -1;//连续n个相同的总分，排名一样
            }
        }
        student[student.length-1].mingci = mingci;
        for (int i = 0; i < student.length; i++) {
            System.out.println(student[i]) ;
        }
    }


    //判断是否连续
    public static int checkContinue(Student[] student,double sum){
        int count = 0 ;//统计多少个连续相同的sum
        for (int i = 0; i < student.length; i++) {
            if(student[i].sum() == sum){
                count++;
            }
        }
        return count;
    }

}
class Student {


    public String name;
    public int  xuehao,mingci,age;
    public double a1, a2, a3;

    Student(int xuehao, String name,int age, double a1, double a2, double a3) {
        this.xuehao = xuehao;
        this.name = name;
        this.age = age;
        this.a1 = a1;
        this.a2 = a2;
        this.a3 = a3;
    }

    double sum() {
        return (this.a1 + this.a2 + this.a3);
    }

    public String toString(){
        return "名次：" + this.mingci + " 学号：" + this.xuehao+" 年龄： "+ this.age+"  "+this.name+" "+this.a1+" "+
                this.a2+" "+this.a3+" 总分:"+this.sum();
    }
}